<template>
	<view class="goods-list">
		<view v-if="type === 'double'" class="goods-double row-between">
			<navigator v-for="(item, index) in list" :key="index" class="item bg-white mt20" hover-class="none"
				open-type="navigate" :url="
          '/pages/goods_details/goods_details?id=' +
          (isBargain ? item.goods_id : item.id)
        ">
				<view class="goods-img" style="width: 347rpx; height: 347rpx">
					<custom-image :lazy-load="true" width="347rpx" height="347rpx" radius="10rpx" lazy-load
						:src="item.image"></custom-image>
				</view>
				<view class="goods-info">
					<view class="goods-name line2">{{ item.name }}</view>
					<view class="price mt10 row">
						<price-format color="#FF2C3C" class="mr10" :first-size="34" :second-size="26"
							:subscript-size="26" :price="item.price" :weight="500"></price-format>
						<price-format class="muted" :firstSize="24" :secondSize="24" :subscript-size="24" line-through
							:price="item.market_price || item.activity_price"></price-format>
					</view>
				</view>
			</navigator>
		</view>
		<view v-if="type === 'hot'" class="goods-hot">
			<navigator v-for="(item, index) in list" :key="index" class="item bg-white mt20 row" hover-class="none"
				open-type="navigate" :url="'/pages/goods_details/goods_details?id=' + item.id">
				<view class="goods-img" style="width: 180rpx; height: 180rpx">
					<custom-image :lazy-load="true" width="180rpx" height="180rpx" radius="6rpx" lazy-load
						:src="item.image"></custom-image>
				</view>
				<view class="goods-info ml20">
					<view class="goods-name line2 mb10">{{ item.name }}</view>
					<text class="sale br60 xxs">已有{{ item.sales_sum }}人购买</text>
					<view class="row-between mt10">
						<view class="price mt10 row">
							<price-format color="#FF2C3C" class="mr10" :first-size="34" :second-size="26"
								:subscript-size="26" :price="item.price" :weight="500"></price-format>
							<price-format class="muted" :firstSize="24" :secondSize="24" :subscript-size="24"
								line-through :price="item.market_price"></price-format>
						</view>
						<image class="icon-md" src="/static/images/icon_go_red.png"></image>
					</view>
				</view>
				<image class="paixu" :src="'/static/images/No.' + (index < 3 ? index : 3) + '.png'"></image>
				<view class="number xxs">{{ index + 1 }}</view>
			</navigator>
		</view>
		<view v-if="type === 'home-hot'" class="goods-home-hot goods-hot">
			<navigator hover-class="none" open-type="navigate" :url="'/pages/goods_details/goods_details?id=' + item.id"
				class="team-item bg-white" v-for="(item, index) in list" :key="index">
				<view class="team-top" v-if="item.sell_etime - item.sell_stime > 0">
					<text class="team-top__title">距结束还有：</text>
					<u-count-down :timestamp="item.sell_etime - item.sell_stime"></u-count-down>
				</view>
				<view class="item row">
					<view class="goods-img">
						<custom-image mode="widthFix" :lazy-load="true" width="296rpx" height="296rpx" radius="16rpx"
							lazy-load :src="item.pics[0]"></custom-image>
					</view>
					<view class="goods-info ml20 mr20">
						<view class="goods-name line2 mb10">{{ item.title }}</view>
						<view class="mb10 xxs">已拼{{ item.sale_num }}件，还剩{{ item.stock }}件</view>
						<!-- <text class="merchant-name mb10 xxs">{{item.merchant.name}}</text> -->
						<view class="" style="
                display: flex;
                align-items: center;
                justify-content: space-between;
              ">
							<view class="goods-price">预付金<text class="unit">￥</text><text class="price">{{
                  item.prepay_amount ? item.prepay_amount / 100 : "0.00"
                }}</text></view>
							<view class="goods-price">团购价<text class="unit">￥</text><text class="price">{{
                  item.price ? item.price / 100 : "0.00"
                }}</text></view>
						</view>
						<view class="goods-button">
							<button open-type="share" catchtap="shareNull" v-bind:data-item="item"
								class="column column-center" hover-class="none">
								<view class="goods-button-item zf"> 转发 </view>
							</button>
							<view class="goods-button-item buy" @click.stop="
                  goPage(
                    '/pages/goods_details/goods_details?action=singleBuy&id=' +
                      item.id
                  )
                ">
								当团长
							</view>
						</view>
					</view>
				</view>
				<view class="team-follow">
					<view class="team-follow__title row-between" v-if="item.last_gruop && item.last_gruop.length">
						<text class="team-follow__title-left">TA们正在团，可跟团</text>
						<text class="team-follow__title-more">查看更多>></text>
					</view>
					<view class="team-follow-bot row-between" v-if="item.last_gruop && item.last_gruop.length">
						<view class="row team-follow-user">
							<view class="team-follow-user__avatar row"
								v-if="item.last_gruop[0].sub_group_orders.length">
								<view class="avatar-image" v-for="(user, user_index) in item.last_gruop[0]
                    .sub_group_orders" :key="user_index">
									<image v-if="user && user.user && user.user.acatar"
										class="team-follow-user__avatar-item" :src="user.user.avatar"></image>
									<image class="team-follow-user__avatar-item" v-else
										src="/static/images/my_portrait_empty.png"></image>
								</view>
								<!-- <block v-if="item.team_data.follows.length < 3">
									<view v-for="i of (3-item.team_data.follows.length)" :key="i" class="team-follow-user__avatar-none">
										<u-icon size="24" color="#666666" name="question"></u-icon>
									</view>
								</block> -->
							</view>
							<view class="team-follow-user__tips">
								<view class="team-follow-user__tips-top">还差<text
										class="team-follow-user__tips-top-strong">{{
                    item.group_limit_num -
                    item.last_gruop[0].sub_group_orders.length
                  }}</text>人拼满，快上车</view>
								<view class="team-follow-user__tips-bot">48小时没拼满自动退款</view>
							</view>
						</view>
						<button type="primary" v-if="item.last_gruop && item.last_gruop.length"
							class="team-follow-bot__btn br60" plain size="xs">
							去参团
						</button>
					</view>
					<view class="row">
						<view class="regiment-tips" v-if="isMarketer">
							<text v-if="item.creator_commission">分享返现￥{{
                  (item.creator_commission / (100 * 1000)).toFixed(2)
                }}</text>
						</view>
						<view class="regiment-tips" v-if="userInfo.new_discount_num===1 || !userInfo.id">
							<text>新用户注册登录领红包￥{{ (item.new_user_discount / 100 ).toFixed(2) }}</text>
						</view>
					</view>
				</view>
				<view class="goods-line"></view>
			</navigator>
		</view>
		<view v-if="type === 'new'" class="goods-new">
			<navigator v-for="(item, index) in list" :key="index" class="item bg-white mt20 row" hover-class="none"
				open-type="navigate" :url="'/pages/goods_details/goods_details?id=' + item.id">
				<view class="goods-img">
					<custom-image :lazy-load="true" width="240rpx" height="240rpx" radius="10rpx" lazy-load
						:src="item.image"></custom-image>
				</view>
				<view class="goods-info ml20 mr20 flex1">
					<view class="goods-name line2 mb20">{{ item.name }}</view>
					<view class="row-between muted xxs">
						<view class="line-through">
							<text>原价</text>
							<price-format :second-size="22" :first-size="22" :subscript-size="22"
								:price="item.market_price"></price-format>
						</view>
						<view>{{ item.sales_sum }}人购买</view>
					</view>
					<view class="row-between mt10">
						<price-format color="#FF2C3C" :first-size="38" :subscript-size="26" :second-size="26"
							:price="item.price" :weight="500"></price-format>
						<button type="primary" class="br60" size="xs">立即抢购</button>
					</view>
				</view>
			</navigator>
		</view>
		<view v-if="type === 'one'" class="goods-one mt20">
			<navigator v-for="(item, index) in list" :key="index" class="item bg-white row" hover-class="none"
				open-type="navigate" :url="'/pages/goods_details/goods_details?id=' + item.id">
				<view class="goods-img" style="width: 200rpx; height: 200rpx">
					<custom-image :lazy-load="true" width="200rpx" height="200rpx" radius="6rpx" lazy-load
						:src="item.image"></custom-image>
				</view>
				<view class="goods-info ml20">
					<view class="goods-name line2 mb10">{{ item.name }}</view>
					<view class="row-between mt10">
						<view class="price mt10 row">
							<price-format color="#FF2C3C" class="mr10" :first-size="34" :second-size="26"
								:subscript-size="26" :price="item.price" :weight="500"></price-format>
							<price-format class="muted" :firstSize="24" :secondSize="24" :subscript-size="24"
								line-through :price="item.market_price"></price-format>
						</view>
					</view>
				</view>
			</navigator>
		</view>
	</view>
</template>

<script>
	import {
		baseURL,
		basePath
	} from "@/config/app";
	import {
		toLogin
	} from "@/utils/login";
	import {
		mapGetters
	} from "vuex";
	import {
		getPlatformActivity,
		getNewUserBenefit
	} from "@/api/activity";

	export default {
		props: {
			type: {
				type: String,
				default: "double",
			},
			list: {
				type: Array,
				default: () => [],
			},
			isBargain: {
				type: Boolean,
				default: false,
			},

		},
		data() {
			return {
				isMarketer: 0,
				clearTimeSet: null,
				userBenefit: {
					redPackBenefit: 0.05,
				},
			};
		},
		computed: {
			...mapGetters(['isLogin', 'userInfo']),
		},
		created() {
			this.clearTimeSet = setInterval(() => {
				this.getMarketer();
			}, 1000);
		},
		mounted() {
			if (!this.isLogin) {
				console.log(this.isLogin, 'this.isLogin');
				// this.getNewUserBenefitData()
			}
		},
		destroyed() {
			clearInterval(this.clearTimeSet);
		},
		methods: {
			getMarketer() {
				const that = this;
				wx.getStorage({
					key: "isMarketer",
					success(res) {
						if (!res.data) {
							that.isMarketer = 0;
						} else {
							that.isMarketer = JSON.parse(res.data);
						}
					},
					fail() {
						that.isMarketer = 0;
					},
				});
			},
			goPage(url) {
				if (!this.isLogin) return toLogin();
				uni.navigateTo({
					url,
				});
			},
			shareNull() {
				console.log("禁止冒泡");
			},
			async getNewUserBenefitData() {
				const {
					code,
					data
				} = await getNewUserBenefit();
				if (code == 1) {
					this.userBenefit = data || {};
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.team-item {
		padding: 0 20upx 20upx;

		.team-top {
			padding: 20upx 0;

			&__title {
				color: #c7c4cc;
			}
		}

		.goods-line {
			width: 100%;
			height: 6rpx;
			background-color: #f8f8f8;
			margin-top: 40rpx;
		}

		.item {
			align-items: flex-start;
		}

		.goods-name {
			// height: 84rpx;
			font-size: 32upx;
			font-weight: 500;
		}

		.merchant-name {
			padding: 4rpx 18rpx;
			color: #000000;
			background-color: #f0f0f0;
			border-radius: 4rpx;
		}

		.goods-price {
			margin-top: 30rpx;
			color: #ff5e61;
			font-size: 20upx;

			text {
				font-size: 30upx;
			}

			.unit {
				font-size: 20upx;
			}

			.price {
				font-weight: bold;
			}
		}

		.goods-button {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 24rpx;

			.goods-button-item {
				border: 2upx solid #ff5e61;
				border-radius: 16rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 24rpx;
				width: 180rpx;
				height: 56rpx;
			}

			.zf {
				background-color: #ffffff;
				color: #ff5e61;
			}

			.buy {
				background-color: #ff5e61;
				color: #ffffff;
			}
		}

		.team-sale-tag {
			color: #a1a1b4;
		}

		.team-origin-price {
			background-color: #ff5e61;
			color: #fff;
			display: inline-block;
			padding: 2upx 16upx;
			border-radius: 6upx;
			font-size: 24upx;
		}

		.team-price {
			color: #ff5e61;
			font-size: 32upx;
			padding: 12upx 0;

			&__title {
				display: inline-block;
				margin-right: 10upx;
			}
		}

		.team-btn-wrap {
			&__btn {
				border-radius: 40upx;
				width: 180upx;
				height: 60upx;

				&-share,
				&-buy {
					border-color: #ff5e61;
					color: #ff5e61;
				}

				&-buy {
					background-color: #ff5e61;
					color: #fff;
				}
			}
		}

		.team-follow {
			padding: 0 20upx;

			&__title {
				padding: 30upx 0 10upx;

				&-left {
					color: #a1a1b4;
				}

				&-more {
					color: #ff5e61;
				}
			}

			&-bot {
				padding: 20upx 0;

				&__btn {
					border-color: #ff5e61;
					color: #ff5e61;
				}
			}

			&-user {
				&__tips {
					&-top {
						color: #352641;
						font-weight: 500;

						&-strong {
							color: #ff5e61;
						}
					}

					&-bot {
						color: #979aab;
					}
				}

				&__avatar {
					margin-right: 20upx;

					// min-width: 156upx;
					&-item,
					&-none {
						width: 48upx;
						height: 48upx;
						border-radius: 48upx;
						margin-right: 6upx;

						&:last-child {
							margin-right: 0;
						}
					}

					&-none {
						background-color: #f2f2f2;
						line-height: 48upx;
						text-align: center;
					}
				}
			}
		}
	}

	.goods-list {
		.goods-double {
			flex-wrap: wrap;
			padding: 0 20rpx;
			align-items: stretch;

			.item {
				width: 347rpx;
				border-radius: 10rpx;

				.goods-info {
					padding: 10rpx;
				}
			}
		}

		.goods-hot {
			&.goods-home-hot {
				.item {
					padding: 0;

					.paixu,
					.number {
						left: 10rpx;
					}
				}
			}

			.item {
				position: relative;
				padding: 30rpx 20rpx;
				border-radius: 10rpx;

				.goods-info {
					width: 450rpx;

					.sale {
						padding: 4rpx 18rpx;
						color: #f79c0c;
						background-color: rgba(247, 156, 12, 0.1);
					}
				}

				.paixu,
				.number {
					position: absolute;
					top: 0;
					left: 27rpx;
					width: 50rpx;
					height: 54rpx;
					line-height: 60rpx;
					text-align: center;
					color: #621e09;
				}
			}
		}

		.goods-one .item {
			padding: 20rpx;

			&:not(:last-of-type) {
				margin-bottom: 20rpx;
			}
		}

		.goods-new .item {
			box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.16);
			border-radius: 10rpx;
		}
	}

	.regiment-tips {
		color: #ff5e61;
		font-size: 22rpx;
		margin-top: 20rpx;

		text {
			margin-right: 16rpx;
		}
	}
</style>